/**
 * Created:	2011-8-3
 * By:		eeorange
 * OS:		Windows/mingw
 * Ques ID:	562 - Dividing Coins
 * Status:	TLE
 * Desc:	force search
 *
 */



#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 1000 + 10;
int A[MAXN], n, Coins[MAXN];
int ans;

void dfs(int *A, int cur)
{
	if(cur == n){
		int a = 0, b = 0;
		for(int i=0; i<n; i++) A[i] ? (a+= Coins[i]) : (b+= Coins[i]);
//		if(ans > abs(a-b)) ans = abs(a-b);
		ans <?= abs(a-b);
	}
	else{
		A[cur] = 0;
		dfs(A, cur+1);
		A[cur] = 1;
		dfs(A, cur+1);
	}
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("data.in", "r", stdin);
	#endif

	int nc;
	cin >> nc;
	while(nc--)
	{
		// init data
		ans = (1<<20);
		// read input
		cin >> n;
		for(int i=0; i < n; i++) cin >> Coins[i];
		dfs(A, 0);
		cout << ans << endl;
	}

	return 0;
}
		
/*
#include <iostream>
using namespace std;

const int MAXN = 1000 + 10;
int A[MAXN], n, Coins[MAXN];
int ans;
void dfs(int *A, int cur){
	if(cur == n)
	{
		int a = 0, b = 0;
		for(int i=0; i< n; i++) 
			if(A[i]) a+= Coins[i];
			else	b+= Coins[i];
		if(ans > abs(a-b)) ans = abs(a-b);
	}
	else
	{
		A[cur] = 0;
		dfs(A, cur+1);
		A[cur] = 1;
		dfs(A, cur+1);
	}
}

int main(){
	// read input
	int nt;
	cin >> nt;
	while(nt--)
	{
		cin >> n;
		for(int i=0; i < n; i++) cin >> Coins[i];
		ans = (1<<20);
		dfs(A, 0);
		cout << ans << endl;
	}

	return 0;
}




/*


#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 50000+10;
int n;
int Min;
int A[MAXN];

void dp(int x, int y, int cur)
{
	if(cur == n){
		if(Min > abs(x-y)) Min = abs(x-y);
	}
	else{
		dp(x+A[cur], y, cur+1);
		dp(x, y+A[cur], cur+1);
	}
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("data.in", "r", stdin);
	#endif

	int nr_cases;
	cin >> nr_cases;
	while(nr_cases--)
	{
		// init
		Min = 100000000;

		cin >> n;
		for(int i=0; i<n; i++) cin >> A[i];
		
		dp(0, 0, 0);
		cout << Min << endl;
	}



	#ifndef ONLINE_JUDGE
		printf("Time used = %.3lf\n", (double)clock()/CLOCKS_PER_SEC);
	#endif
	return 0;
}

*/

